package com.adnaan.restaurant.service.impl;

import com.adnaan.restaurant.common.untils.PageResult;
import com.adnaan.restaurant.common.untils.PageUtils;
import com.adnaan.restaurant.entity.ResOrder;
import com.adnaan.restaurant.mapper.ResOrderMapper;
import com.adnaan.restaurant.service.IResOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author: adnaan
 * create: 2023-12-10 20:16
 * Description:
 */
@Service
public class ResOrderServiceImpl implements IResOrderService {

    @Autowired
    private ResOrderMapper resOrderMapper;

    @Override
    public PageResult getMyOrder(Long userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ResOrder> resOrderList = resOrderMapper.getMyOrder(userId);
        if (resOrderList.size() == 0) {
            return null;
        }
        PageInfo<ResOrder> resOrderPageInfo = new PageInfo<>(resOrderList);
        PageResult pageResult = PageUtils.getPageResult(resOrderPageInfo);
        return pageResult;
    }

    @Override
    public int buy(ResOrder resOrder) {
        return resOrderMapper.buy(resOrder);
    }
}
